home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / themous.com / MOUSDRAW.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-01-02  |  7.6 KB  |  220 lines

  1. Program Mouse_Draw;
  2.  
  3. (*                                                   *)
  4. (*          An Example Program for TheMouse          *)
  5. (*      A Turbo Pascal Mouse Unit by Kevin Kwast     *)
  6. (*                                                   *)
  7.  
  8. Uses Graph, Crt, TMouse5;    {Change to TMouse4 if using Turbo Pascal 4}
  9.  
  10. Type
  11.     gCurs = Array[1..32] of Word;
  12.     gCursRec = Record
  13.                  Image: gCurs;
  14.                  HotX, HotY: Word;
  15.                End;
  16.  
  17. Const
  18.      CrayonImage: GCurs = ($FFF1, $FFE0, $FFC0, $FF80,
  19.                            $F300, $FE01, $FC03, $F807,
  20.                            $F00F, $E01F, $C03F, $807F,
  21.                            $00FF, $01FF, $03FF, $87FF,
  22.                            $0000, $000E, $001F, $0037,
  23.                            $0066, $00CC, $0198, $0330,
  24.                            $0660, $0CC0, $1980, $3300,
  25.                            $6600, $6C00, $7800, $2000);
  26.  
  27. (*
  28.   The field used in the graphics cursor mask is defined as follows:
  29.  
  30.   The mask must be an array of 32 words, the first 16 are the "screen mask"
  31.   and the second 16 words are the "cursor mask". The device driver ANDs the
  32.   screen mask with the 16 x 16 bit screen area where the cursor is being
  33.   displayed, and then XORs the cursor mask with that result, producing these
  34.   results:
  35.  
  36.   Screen Mask Bit              Cursor Mask Bit             Display Bit
  37.  
  38.         0                            0                          0
  39.         0                            1                          1
  40.         1                            0                       Unchanged
  41.         1                            1                       Inverted
  42.  
  43.   Each mask is a 16 x 16 bit data area. It can be seen easier by drawing out
  44.   the bits for each mask. The crayon used in this program looks like this:
  45.  
  46.            Screen Mask                      Cursor Mask
  47.  
  48.          1111111111110001                 0000000000000000
  49.          1111111111100000                 0000000000001110
  50.          1111111111000000                 0000000000011111
  51.          1111111110000000                 0000000000110111
  52.          1111111100000000                 0000000001100110
  53.          1111111000000001                 0000000011001100
  54.          1111110000000011                 0000000110011000
  55.          1111100000000111                 0000001100110000
  56.          1111000000001111                 0000011001100000
  57.          1110000000011111                 0000110011000000
  58.          1100000000111111                 0001100110000000
  59.          1000000001111111                 0011001100000000
  60.          0000000011111111                 0110011000000000
  61.          0000000111111111                 0110110000000000
  62.          0000001111111111                 0111100000000000
  63.          1000011111111111                 0010000000000000
  64.  
  65.   Notice that the screen mask is the size of the cursor mask and a little
  66.   larger for the black outline effect.
  67.  
  68. *)
  69.  
  70. Var
  71.     Crayon : GCursRec;
  72.  
  73.     Done: Boolean;
  74.  
  75.     gd, gm: integer;
  76.  
  77.     tmInit: TheMouseInitType;
  78.     tmInfo: TheMouseInfoType;
  79.     tmEvent: TheMouseEventType;
  80.  
  81. (***  Here is the event handler..  ***)
  82.  
  83. {$F+}         { Far Calls for Event Handler }
  84.  
  85. Procedure Event(Flags, CS, AX, BX, CX, DX, SI, DI, DS, ES, BP: Word);
  86.  
  87. {This will be called by the mouse driver, and must have this format}
  88. Interrupt;
  89.  
  90. Begin
  91.      tmEvent.EventMask := AX;
  92.      tmEvent.ButtonStatus := BX;
  93.      tmEvent.Column := CX;
  94.      tmEvent.Row := DX;
  95.  
  96.      Inline (            { exit for far return to mouse device driver }
  97.       $8B/$E5/     { Mov SP,BP }
  98.       $5D/         { Pop BP }
  99.       $07/         { Pop ES }
  100.       $1F/         { Pop DS }
  101.       $5F/         { Pop DI }
  102.       $5E/         { Pop SI }
  103.       $5A/         { Pop DX }
  104.       $59/         { Pop CX }
  105.       $5B/         { Pop BX }
  106.       $58/         { Pop AX }
  107.       $CB );       { RetF }
  108. End;
  109.  
  110. {$F-}
  111.  
  112. Procedure TopMessage(S: String);
  113. Var X, Y: Word;
  114. Begin
  115.      SetViewPort(0,0,GetMaxX,28,False);
  116.      ClearViewPort;
  117.      SetViewPort(0,0,GetMaxX,GetMaxY,False);
  118.  
  119.      SetTextStyle(DefaultFont, HorizDir, 1);
  120.      X:=(GetMaxX - TextWidth(S)) div 2;
  121.      Y:=13 - (TextHeight(S) div 2);
  122.      OutTextXY(X,Y,S);
  123.      Line(0,27,GetMaxX,27);
  124. End;
  125.  
  126. Procedure BottomMessage(S: String);
  127. Var X, Y: Word;
  128. Begin
  129.      SetViewPort(0,GetMaxY-17,GetMaxX,GetMaxY,False);
  130.      ClearViewPort;
  131.      SetViewPort(0,0,GetMaxX,GetMaxY,False);
  132.  
  133.      SetTextStyle(DefaultFont, HorizDir, 1);
  134.      X:=(GetMaxX - TextWidth(S)) div 2;
  135.      Y:=(GetMaxY - 9) - (TextHeight(S) div 2);
  136.      OutTextXY(X,Y,S);
  137.      Line(0,GetMaxY-18,GetMaxX,GetMaxY-18);
  138. End;
  139.  
  140.  
  141. Begin
  142.      With Crayon do
  143.      Begin
  144.           Image:=CrayonImage;
  145.           HotX:=3;
  146.           HotY:=16;
  147.      End;
  148.  
  149.      tmReset(tmInit);
  150.      If NOT tmInit.Exists then Begin
  151.                                     WriteLn('Mouse driver not found.');
  152.                                     Halt;
  153.                                End;
  154.  
  155.      Gd:=CGA; Gm:=CGAHi;
  156.      InitGraph(Gd, Gm, 'C:\TURBO\BGI');   {Put the location of your BGI files}
  157.      If GraphResult <> grOk then Begin
  158.                                     WriteLn('Error loading graphics system.');
  159.                                     Halt;
  160.                                  End;
  161.  
  162.      TopMessage('MouseDraw example for TheMouse');
  163.      BottomMessage('Hold Down Left: Draw          Right: Command Mode');
  164.  
  165.      tmColRange(2,GetMaxX-4);
  166.      tmRowRange(30,GetMaxY-20);
  167.      tmGraphCursor(Crayon.HotX, Crayon.HotY, Seg(Crayon.Image), Ofs(Crayon.Image));
  168.      tmCursor(True);
  169.  
  170.      tmTask($55, Seg(Event), Ofs(Event));   {Set up Event handler}
  171.  
  172.      (* Task will trigger on movement, or on any button release *)
  173.  
  174.      Done:=False;
  175.  
  176.      Repeat
  177.  
  178.      tmEvent.EventMask:=0;      { Make sure it doesn't get previous results }
  179.      REPEAT UNTIL (tmEvent.EventMask <> 0);
  180.      CASE tmEvent.EventMask OF
  181.        $0001: Begin               {any motion}
  182.                    If tmEvent.buttonstatus = 1 then    {Left Button Down}
  183.                       Begin
  184.                            tmCursor(False);    {Be sure cursor is off here}
  185.                            PutPixel(tmEvent.Column, tmEvent.Row, 1);
  186.                            tmCursor(True);     {Now turn it back on}
  187.                       End;
  188.               End;
  189.        $0010: Begin               {right button release with no movement}
  190.                    BottomMessage('Now:  Left: Quit   Middle: Abort   Right: Clear    ');
  191.                    tmPos(tmInfo);       {Save cursor location}
  192.                    tmCursor(False);        {Turn cursor off}
  193.                    Repeat
  194.                    tmEvent.EventMask:=0;
  195.                    REPEAT UNTIL tmEvent.EventMask <> 0;
  196.                    tmEvent.EventMask:=tmEvent.EventMask and $54;
  197.                    CASE tmEvent.EventMask OF
  198.                      $04: Done:=True;
  199.                      $10: Begin
  200.                                  tmCursor(False);
  201.                                  SetViewPort(0, 30, GetMaxX, GetMaxY-19,False);
  202.                                  ClearViewPort;
  203.                                  tmCursor(True);
  204.                           End;
  205.                      $40: ;       {Do Nothing}
  206.                    ELSE tmEvent.EventMask:=0;
  207.                    END;
  208.                    Until (tmEvent.EventMask <> 0);
  209.                    tmMoveTo(tmInfo.Column, tmInfo.Row);
  210.                    tmCursor(True);              {Put Cursor Back}
  211.                    BottomMessage('Hold Down Left: Draw          Right: Command Mode');
  212.               End;
  213.      END;
  214.  
  215.      Until Done;
  216.  
  217.      tmReset(tmInit);
  218.      CloseGraph;
  219. End.
  220.